<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="输入搜索" prop="name">
        <el-input v-model="queryParams.bucketName" placeholder="垃圾站名称" clearable style="width: 300px;" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table ref="tables" v-loading="loading" :data="list" v-if="!loading">
      <el-table-column label="垃圾站编号" align="center" prop="bucketNumber" />
      <el-table-column label="垃圾站名称" align="center" prop="name" />
      <el-table-column label="垃圾站分类" align="center" prop="type">
        <template>
          <div>垃圾站</div>
        </template>
      </el-table-column>
      <el-table-column label="最大容量(m³)" align="center" prop="capacity" />
      <el-table-column label="预警值(%)" align="center" prop="thresholdValue" />
      <el-table-column label="已用容量(m³)" align="center" prop="threshold">
        <template slot-scope="{ row }">
          <div>{{ row.threshold || 0 }}</div>
        </template>
      </el-table-column>
      <el-table-column label="定位位置" align="center">
        <template slot-scope="{ row }">
          <div>{{ row.locationName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.status == 0">已启用</div>
          <div v-else style="color: red">已停用</div>
        </template>
      </el-table-column>
      <el-table-column label="预警状态" align="center">
        <template slot-scope="{ row }">
          <div v-if="row.maxStatus == 1" style="color: rgb(255, 94, 0)">满溢预警</div>
          <div v-else-if="row.maxStatus == 2" style="color: red">超出容量</div>
          <div v-else>--</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleDetail(scope.row.id)">满溢情况</el-button>
          <el-button size="mini" type="text" @click="video(scope.row)">视频监控</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { bucketList, addbucket, editbucket, delbucket, changebucket } from "@/api/system/resource";
import { getLocationName } from '@/utils/map'

export default {
  name: "Operlog",
  data() {
    return {
      rules: {
        name: [
          { required: true, message: '请填写名称', trigger: 'blur' },
        ],
        num: [
          { required: true, message: '请填写编号', trigger: 'blur' },
        ],
      },
      title: '添加垃圾站',
      editId: null,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 表单参数
      form: { bucketNumber: '', name: '', type: '', areaLocation: {}, capacity: '', thresholdValue: "" },
      formlocationName: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bucketName: undefined,
        type: 2
      },
      open: false,
      classifyList: [{
        name: '垃圾桶',
        type: 0
      },
      {
        name: '垃圾箱',
        type: 1
      },
      {
        name: '垃圾站',
        type: 2
      }],
      openMap: false,
      map: null,
      marker: null,
      center: [116.122046, 24.288832],
    };
  },

  created() {
    this.getList();
  },
  methods: {
    /** 查询登录日志 */
    async getList() {
      this.loading = true;
      const res = await bucketList(this.queryParams);
      if (res.code === 200) {
        this.list = res.data.records;
        for (const item of this.list) {
          if (item.jsonString) {
            const jsonObj = JSON.parse(item.jsonString);
            const lnglat = { lng: jsonObj.longitude, lat: jsonObj.latitude };
            item.locationName = await getLocationName(lnglat);
          }
        }
        this.total = res.data.total;
        this.loading = false;
        return;
      }
      this.$modal.msgSuccess(res.msg);
    },
    //查看视频监控
    video(row) {
      this.$router.push({ path: '/control/dumpVideo', query: { id: row.id } })
    },
    //满溢情况
    handleDetail(){},
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
  },

};
</script>
<style lang="scss" scoped>
.manage-add-btn {
  float: right;
}

.dialog-footer {
  text-align: center;
}
</style>
